﻿//服务端控件ID获取
var ClientIds = getClientIds();
var handlerPage = '/Common/Services/BaseInfoFormHandler.aspx';

function CheckInsuranceCode(obj) {
    var params = { imgId: "InsuranceCodeChecking",
        validateId: "InsuranceCode",
        vallidateValue: $(obj).val() + "|" + $(ClientIds.baseInfoID).val(),
        validateObj: obj,
        callback: "CheckInsuranceCodeCallback"
    };
    GoCheck(params);
}

function CheckInsuranceCodeCallback(result, id) {
    if (result === "True") {
        alert('该单位社保号已经存在，请勿重复添加！');
        $('#' + id).val('');
        $('#' + id).focus();
    }
}

function CheckUnitName(obj) {
    var params = { imgId: "UnitNameChecking",
        validateId: "UnitName",
        vallidateValue: $(obj).val() + "|" + $(ClientIds.type).val() + "|" + $(ClientIds.baseInfoID).val(),
        validateObj:obj,
        callback:"CheckUnitCallback"
    };
    GoCheck(params);
}

function CheckUnitCallback(result, id) {
    if (result === "True") {
        if (!confirm('该单位名称已经存在，您确定要继续添加？')) {
            $('#' + id).val('');
            $('#' + id).focus();
        }
    }
}

function CheckTaxCode(obj) {
    var params = { imgId: "TaxCodeChecking",
        validateId: "TaxCode",
        vallidateValue: $(obj).val() + "|" + $(ClientIds.type).val() + "|" + $(ClientIds.baseInfoID).val(),
        validateObj: obj,
        callback: "CheckTaxCodeCallback"
    };
    GoCheck(params);
}

function CheckTaxCodeCallback(result, id) {
    if (result === "True") {
        if (!confirm('该纳税编码已经存在，您确定要继续添加？')) {
            $('#' + id).val('');
            $('#' + id).focus();
        }
    }
}

function GoCheck(params) {
    
    $('#' + params.imgId).show();

    jQuery.ajax({
        url: handlerPage,
        type: "GET",
        dataType: "text",
        async: true,
        data: {
            method: 'ValidateValue',
            validateId: params.validateId,
            validateValue: params.vallidateValue,
            t: new Date().getTime()
        },
        success: function (data) {
            eval(params.callback + "('" + data + "','" + params.validateObj.id + "')");
            $('#' + params.imgId).hide();
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert('系统错误 status:' + XMLHttpRequest.status + ' readyState:' + XMLHttpRequest.readyState + ' textStatus:' + textStatus);
            $('#' + params.imgId).hide();
        },
        complete: function (XMLHttpRequest, textStatus) {
            this; // 调用本次AJAX请求时传递的options参数
        }
    });
}